<template>

	<view class="container">

		<!-- 头部轮播 -->
		<view class="carousel-section">
			<view class="titleNview-placing"></view>
			<swiper class="carousel" circular @change="swiperChange" :autoplay="true" :interval="4000">
				<swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item">
					<img :src="item.photo" />
				</swiper-item>
			</swiper>
			<view class="swiper-dots">
				<text class="num">{{swiperCurrent+1}}</text>
				<text class="sign">/</text>
				<text class="num">{{this.carouselList.length}}</text>
			</view>
		</view>

		<!-- 分类 -->
		<div class="glass-div">
			<div class="classificationDiv">
				<div class="classificationDivItem" v-for="(item,index) in classification" :key="index">
					<img :src="item.icon" alt="" />
					<p>{{item.title}}</p>
				</div>
			</div>
			<u-scroll-list>
				<view class="classificationDivItem1" v-for="(item, index) in jingangDistrict" :key="index">
					<img :src="item.icon"></img>
					<p>{{item.name}}</p>
				</view>
			</u-scroll-list>
		</div>

		<view style="margin:0 20rpx;">
			<!-- 公告 -->
			<noticePage />
		</view>

		<view class="ad-1">
			<image src="/static/temp/ad1.jpg" mode="scaleToFill"></image>
		</view>
		<!-- 活动日历 -->
		<view class="activity-Div">
			<view style="display: flex;justify-content: space-between;">
				<p>活动日历</p>
				<span>更多></span>
			</view>
			<view style="display: flex;justify-content: space-around;width: 100%;">
				<view class="activity-Div-item" @click="navToDetailPage(recommend.id,1)">
					<image :src="recommend.photo[0]" mode="aspectFill"></image>
					<view>
						<view class="activity-Div-div">{{recommend.name}}</view>
						<view style="font-size: 28rpx;color: orange;">
							￥{{recommend.sellingPrice}}
							<span style="font-size: 20rpx;">起</span>
						</view>
					</view>
				</view>
				<view class="activity-Div-item" @click="navToDetailPage(recommend.id,1)">
					<image :src="recommend.photo[0]" mode="aspectFill"></image>
					<view>
						<view class="activity-Div-div">{{recommend.name}}</view>
						<view style="font-size: 28rpx;color: orange;">
							￥{{recommend.sellingPrice}}
							<span style="font-size: 20rpx;">起</span>
						</view>
					</view>
				</view>
				<view class="activity-Div-item" @click="navToDetailPage(recommend.id,1)">
					<image :src="recommend.photo[0]" mode="aspectFill"></image>
					<view>
						<view class="activity-Div-div">{{recommend.name}}</view>
						<view style="font-size: 28rpx;color: orange;">
							￥{{recommend.sellingPrice}}
							<span style="font-size: 20rpx;">起</span>
						</view>
					</view>
				</view>
			</view>
		</view>


		<!-- 热门推荐 -->
		<view class="recommend-Div">
			<view style="display: flex;justify-content: space-between;" @click="goRecommendList">
				<p>热力推荐榜
					<span>全网热搜的热门打卡地</span>
				</p>
				<span style="font-size: 24rpx;">更多></span>
			</view>
			<view class="recommendDiv">

				<view class="recommendDivLeft">
					<span style="font-size: 26rpx;color: #ffffff;margin-left: 54rpx;line-height: 60rpx;">景区榜</span>
					<view class="recommendDivLeft-bot">
						<view class="recommendDivLeft-item" v-for="(item,index) in scenicSpotList" :key="index"
							@click="jumpTo(item)">
							<image :src="item.photo[0]" mode="aspectFill"></image>
							<view style="margin-left: 20rpx;">
								<view class="recommendDivLeft-item-div">
									{{item.name}}
								</view>
								<view class="recommendDivLCen-item-div">
									{{item.label}}
								</view>
								<view class="recommendDivBot-item-div" style="font-size: 26rpx;">
									{{item.level}}A
								</view>
							</view>
						</view>
					</view>
				</view>

				<view class="recommendDivRight">
					<view class="topDiv">
						<span style="font-size: 26rpx;color: #ffffff;margin-left: 54rpx;line-height: 60rpx;">民宿榜</span>
						<view class="recommendDivLeft-item" @click="jumpToM(hotelsData)">
							<image :src="hotelsData.photo[0]" mode="aspectFill"></image>
							<view style="margin-left: 20rpx;">
								<view class="recommendDivLeft-item-div">
									{{hotelsData.name}}
								</view>
								<view class="recommendDivLeft-item-div" style="font-size: 26rpx;">
									￥{{hotelsData.averageprice}}起</view>
							</view>
						</view>
					</view>

					<view class="topDiv">
						<span style="font-size: 26rpx;color: #ffffff;margin-left: 54rpx;line-height: 60rpx;">商品榜</span>
						<view class="recommendDivLeft-item" @click="navToDetailPage(recommend.id,1)">
							<image :src="recommend.photo[0]" mode="aspectFill"></image>
							<view style="margin-left: 20rpx;">
								<view class="recommendDivLeft-item-div">
									{{recommend.name}}
								</view>
								<view class="recommendDivLeft-item-div" style="font-size: 26rpx;">
									￥{{recommend.sellingPrice}}起</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 攻略推荐 -->
		<view class="guessSectionDiv">
			<p>热力攻略榜</p>
			<u-sticky>
				<view class="guessSectionDiv-tabs">
					<u-tabs :list="strategyGuideList" @click="clickGuideList"></u-tabs>
				</view>
			</u-sticky>
			<scroll-view scroll-y="true" style="height: 100vh;" refresher-background="#FFF" @scrolltolower="loadMore">
				<view class="guess-section">
					<view v-for="(item, index) in strategyGuide" :key="index" class="guess-item"
						@click="navToDetailPage(item.id,0)">
						<view class="image-wrapper">
							<image :src="item.photo[0]" mode="aspectFill"></image>
						</view>
						<view class="guess-item-top">{{item.title}}</view>
						<view class="guess-item-bot">
							<span>{{item.author}}</span>
							<span style="display: flex;align-items: center;gap: 10rpx;"><u-icon
									name="eye"></u-icon>{{item.likeCount}}</span>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 底部的菜单 -->
		<customTabBar></customTabBar>
	</view>

</template>

<script>
	import {
		getIndexSlideshow,
		getIndexMenu,
		getnewsGuide,
		browsingHistoryAdd,
		scenicAreaRecommendation,
		commodityRecommendation,
		hotels
	} from '@/api/home.js'
	import noticePage from "../../components/noticePage.vue";
	import {
		nextTick
	} from "vue";
	export default {
		components: {
			noticePage
		},
		data() {
			return {
				// 轮播图第几张
				swiperCurrent: 0,
				// 轮播图的数据
				carouselList: [],
				// 商品推荐
				recommend: {},
				// 猜你喜欢,攻略
				strategyGuide: [],
				clickGuideName: '',
				// 金刚区
				jingangDistrict: [],
				// 大分类
				classification: [{
						id: 1,
						title: '酒店',
						icon: '/static/home/jiudian1.png'
					},
					{
						id: 2,
						title: '攻略/景点',
						icon: '/static/home/jingdian.png'
					},
					{
						id: 3,
						title: '机票',
						icon: '/static/home/jipiao.png'
					},
					{
						id: 4,
						title: '火车票',
						icon: '/static/home/huoche.png'
					},
					{
						id: 5,
						title: '旅游/跟团',
						icon: '/static/home/lvyou.png'
					},
				],
				strategyGuideList: [{
					name: '全部'
				}, {
					name: '景区攻略',
				}, {
					name: '住宿攻略',
				}, {
					name: '线路攻略'
				}, {
					name: '美食攻略'
				}],
				isFixed: false,
				stickyOffset: 0,
				pageSize: 5,
				scenicSpotList: [],
				hotelsData: {},
			};
		},
		onLoad() {
			this.getSlideshow()
			this.getIndexMenu()
			this.getRecommend()
			this.getGuide()
			this.getScenicSpot()
			this.getHotelsData()
		},
		methods: {
			// 跳转到民宿详情
			jumpToM(item) {
				uni.navigateTo({
					url: `/pages/homestayDetails/homestayDetails?id=${item.id}`
				})
			},
			// 跳转到详情页面
			jumpTo(item) {
				uni.navigateTo({
					url: `/pages/scenicSpotDetails/scenicSpotDetails?id=${item.id}`
				})
			},
			// 点击跳转到推荐列表
			goRecommendList() {
				uni.navigateTo({
					url: '/pages/recommendList/recommendList'
				})
			},
			// 获取热力帮景区
			async getScenicSpot() {
				let res = await scenicAreaRecommendation()
				if (res.code == 200) {
					console.log(res, 333, '景区');
					this.scenicSpotList = res.data.slice(0, 3)
				}
			},
			// 下拉加载
			loadMore() {
				this.pageSize = this.pageSize + 5
				this.getGuide()
			},
			// 猜你喜欢,攻略
			async getGuide() {
				let par = {
					pageNum: 1,
					pageSize: this.pageSize,
					type: this.clickGuideName ? this.clickGuideName == '全部' ? '' : this.clickGuideName : ""
				}
				let res = await getnewsGuide(par)
				if (res.code == 200) {
					this.strategyGuide = res.data.records
				}
			},
			// 推荐攻略赛选
			clickGuideList(item) {
				this.clickGuideName = item.name
				this.getGuide()
			},
			// 获取轮播图数据
			async getSlideshow() {
				let res = await getIndexSlideshow('用户端')
				if (res.code == 200) {
					this.carouselList = res.data
				}
			},
			//轮播图切换
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
			},
			// 获取金刚区数据
			async getIndexMenu() {
				let res = await getIndexMenu('用户端')
				if (res.code == 200) {
					this.jingangDistrict = res.data
				}
			},
			// 获取商品推荐数据
			async getRecommend() {
				let res = await commodityRecommendation()
				if (res.code == 200) {
					console.log(res, 222222, '商品');
					this.recommend = res.data[0]
				}
			},
			async getHotelsData() {
				let res = await hotels()
				if (res.code == 200) {
					console.log(res, 999, '住宿');
					this.hotelsData = res.data[0]
				}
			},

			//跳转详情页
			async navToDetailPage(id, num) {
				let par = {
					strategyCommodityId: id,
					type: num,
					userId: wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo').userId : ''
				}
				let res = await browsingHistoryAdd(par)
				if (res.code == 200) {
					if (num == 1) {
						uni.navigateTo({
							url: `/pages/product/product?id=${id}`
						})
					} else if (num == 0) {
						uni.navigateTo({
							url: `/pages/detail/detail?id=${id}`
						})
					}

				}

			},
		},
		// #ifndef MP
		// 标题栏input搜索框点击
		onNavigationBarSearchInputClicked: async function(e) {
			this.$api.msg('点击了搜索框');
		},
		//点击导航栏 buttons 时触发
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.$api.msg('点击了扫描');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		}
		// #endif
	}
</script>

<style lang="scss">
	/* #ifdef MP */
	page {
		.u-scroll-list {
			padding: 30rpx 20rpx;

		}


		.mp-search-box {
			position: absolute;
			right: 50%;
			top: 30upx;
			z-index: 9999;
			width: 80%;
			height: 60rpx;
			padding: 0 40upx;
			border-radius: 10rpx;
			border: 1px solid #2979ff;
			transform: translate(50%, 0);
			margin: auto;


		}

		.carousel-section {
			padding: 0;
			z-index: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}
	}

	/* #endif */

	.glass-div {
		margin-top: -20rpx;
		background: rgba(255, 255, 255, 0.1);
		/* 半透明背景 */
		border-radius: 30rpx 30rpx 0 0;
		box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
		backdrop-filter: blur(5px);
		/* 毛玻璃效果 */
		-webkit-backdrop-filter: blur(5px);
		/* 兼容 Safari */
		border: 1px solid rgba(255, 255, 255, 0.3);

		.classificationDiv {
			display: flex;
			align-items: center;
			justify-content: space-around;
			padding-top: 20rpx;
			border-radius: 20rpx 20rpx 0 0;

			.classificationDivItem {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 10rpx;

				p {
					font-size: 24rpx;
				}

				img {
					width: 100rpx;
					height: 100rpx;
				}
			}
		}

		.classificationDivItem1 {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin-right: 40rpx;

			p {
				font-size: 24rpx;
				white-space: nowrap;
			}

			img {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.activity-Div {
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		padding: 20rpx;

		.activity-Div-item {
			.activity-Div-div {
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				width: 200rpx;
			}

			image {
				width: 220rpx;
				height: 150rpx;
				border-radius: 20rpx 20rpx 0 0;
			}
		}

		p {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}

		span {
			font-size: 24rpx;
			margin-left: 20rpx;
			font-weight: normal;
		}
	}

	.recommend-Div {
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		padding: 20rpx;

		p {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 20rpx;

			span {
				font-size: 24rpx;
				margin-left: 20rpx;
				font-weight: normal;
			}
		}

		.recommendDiv {
			display: flex;
			justify-content: space-between;

			.recommendDivRight {
				display: flex;
				align-items: center;
				flex-direction: column;
				width: 49%;

				.topDiv {

					width: 100%;
					height: 227rpx;
					background-image: url('/static/home/2.png');
					background-size: 100% 100%;
					background-position: center;
					position: relative;


					.recommendDivLeft-item {
						position: absolute;
						top: 90rpx;
						left: 50%;
						margin: auto;
						transform: translate(-50%, 0);
						display: flex;
						align-items: center;

						.recommendDivLeft-item-div {
							font-size: 30rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							width: 120rpx;
						}

						image {
							width: 160rpx;
							height: 100rpx;
							border-radius: 20rpx;
						}
					}
				}
			}

			.recommendDivLeft {
				width: 50%;
				height: 450rpx;
				background-image: url('/static/home/1.png');
				background-size: 100% 100%;
				position: relative;

				.recommendDivLeft-bot {
					position: absolute;
					top: 70rpx;
					left: 50%;
					transform: translate(-50%, 0);
					display: flex;
					// justify-content: space-between;
					gap: 10rpx;
					flex-direction: column;
					height: 310rpx;

					.recommendDivLeft-item {
						display: flex;
						align-items: center;

						.recommendDivLCen-item-div {
							font-size: 24rpx;
							width: 120rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}

						.recommendDivLeft-item-div {
							font-size: 30rpx;
							width: 120rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}

						.recommendDivBot-item-div {
							font-size: 18rpx !important;
							width: 40rpx;
							height: 40rpx;
							padding: 10rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							background-color: #ff7600;
							border-radius: 40rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							color: #fff;
						}

						image {
							width: 160rpx;
							height: 100rpx;
							border-radius: 20rpx;
						}
					}
				}

			}
		}
	}

	page {
		background: #f5f5f5;
	}

	.m-t {
		margin-top: 16upx;
	}

	.u-scroll-list {
		padding: 30rpx 20rpx;

	}

	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
		padding-top: 10px;
		z-index: 0;

		.swiper-dots {
			display: flex;
			position: absolute;
			left: 60upx;
			bottom: 15upx;
			width: 72upx;
			height: 36upx;
			background-image: url();
			background-size: 100% 100%;

			.num {
				width: 36upx;
				height: 36upx;
				border-radius: 50px;
				font-size: 24upx;
				color: #fff;
				text-align: center;
				line-height: 36upx;
			}

			.sign {
				position: absolute;
				top: 0;
				left: 50%;
				line-height: 36upx;
				font-size: 12upx;
				color: #fff;
				transform: translateX(-50%);
			}
		}

		.carousel {

			.carousel-item {
				width: 100%;
				height: 100%;
			}

			img {
				width: 100%;
				height: 100%;
			}
		}

		.titleNview-placing {
			height: var(--status-bar-height);
			padding-top: 44px;
			box-sizing: content-box;
		}

		.titleNview-background {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 426upx;
			transition: .4s;
		}
	}

	.ad-1 {
		width: 100%;
		height: 210upx;
		padding: 10upx 0;
		background: #fff;
		border-radius: 20rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}



	/* 猜你喜欢 */
	.guessSectionDiv {
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		padding: 20rpx 20rpx 140rpx;

		.guessSectionDiv-tabs {
			background-color: #fff;
		}

		p {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 20rpx;

		}

		.guess-section {
			display: flex;
			flex-wrap: wrap;

			.guess-item {
				display: flex;
				flex-direction: column;
				width: 48%;
				padding-bottom: 20upx;
				background: #fff;
				margin: 20rpx 0;
				border-radius: 20rpx;
				box-shadow: 0 0 16rpx rgba(0, 0, 0, 0.2);

				.guess-item-top {
					margin-bottom: 20rpx;
					white-space: nowrap;
					/* 禁止文本换行 */
					overflow: hidden;
					/* 隐藏超出的内容 */
					text-overflow: ellipsis;
					/* 超出部分用省略号表示 */
					width: 100%;
					padding-left: 20rpx;
					padding-right: 20rpx;
				}

				.guess-item-bot {
					font-size: 24rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-left: 20rpx;
					padding-right: 20rpx;
				}

				&:nth-child(2n+1) {
					margin-right: 4%;
				}
			}

			.image-wrapper {
				width: 100%;
				height: 330upx;
				border-radius: 3px;
				overflow: hidden;
				border-radius: 20rpx 20rpx 0 0;


				image {
					width: 100%;
					height: 100%;
					opacity: 1;
				}
			}

			.title {
				font-size: $font-lg;
				color: $font-color-dark;
				line-height: 80upx;
			}

			.price {
				font-size: $font-lg;
				color: $uni-color-primary;
				line-height: 1;
			}
		}
	}
</style>